package com.geovis.emergency.spd.biz.pc.wrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.geovis.common.mybatis.page.PageResult;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 基础包装类
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/6/10
 */
public abstract class BaseEntityWrapper<E, V> {
    public BaseEntityWrapper() {
    }

    public abstract V entityVO(E entity);

    public List<V> listVO(List<E> list) {
        return (List)list.stream().map(this::entityVO).collect(Collectors.toList());
    }

    public PageResult<V> pageVO(PageResult<E> pages) {
        List<V> records = this.listVO(pages.getRecords());
        IPage<V> pageVo = new Page();
        pageVo.setTotal(pages.getTotal());
        pageVo.setRecords(records);
        return new PageResult<>(pageVo);
    }
}